package xyz.zq.cloud.common.log.event;

import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.scheduling.annotation.Async;
import xyz.zq.cloud.bs.api.entity.Log;
import xyz.zq.cloud.bs.api.feign.RemoteLogService;
import xyz.zq.cloud.common.core.constant.SecurityConstants;
import xyz.zq.cloud.common.log.annotation.SysLog;

/**
 * 异步监听日志事件
 *
 * @author hzq
 * @date 2020/4/28 20:21
 */
@Slf4j
@AllArgsConstructor
public class SysLogListener {

    private final RemoteLogService remoteLogService;

    @Async
    @Order
    @EventListener(SysLogEvent.class)
    public void saveSysLog(SysLogEvent event) {
        Log sysLog = (Log) event.getSource();
        remoteLogService.saveLog(sysLog, SecurityConstants.FROM_IN);
    }
}
